Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #110
What
TOP_RATEDsorts wines with at least 50 ratings first, then the rest. Within each part it sorts as before: average, then number of ratings, then id. The limit isTOP_RATED_MIN_COUNTinwine-query.ts.wine_top_ratedwith one that follows the new order, so the first page is read from the index instead of sorting all 100 646 wines.docs/api.mdexplain the choice.Why
The first page of «Best vurdert» was led by wines with 5.0 from 5–6 ratings, ahead of wines with 4.9 from over 150. On the Full dataset every wine has at least 5 ratings, and the median is about 58. With 50 as the limit, 56 333 wines (56 %) qualify.
Wines under the limit are not hidden, only sorted after the others, so
totalCountis the same for every sort order. We considered a weighted average (as on IMDb), but it needs its own stored column to be fast.How to test
npm run db:migrateinbackend/.npm run checkfrom the root./sokwith «Best vurdert»: no wine on the first page has fewer than 50 ratings.After merge, on the VM
Run
npm run db:migrateinbackend/. Then check inpsqlthat the index is used:It should say
Index Scan using wine_top_rated.